package com.qf.springbootproject.controller;

import com.qf.springbootproject.pojo.User;
import io.swagger.annotations.Api;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/thy")
@Api(tags = "测试Thymeleaf使用接口文档")
public class ThymeleafController {

    /**
     * 测试进入 Thymeleaf页面
     * @param model
     * @return
     */
    @RequestMapping("/test1")
    public String test404(Model model){
        User user = new User("1","dew","45");
        model.addAttribute("user",user);
        return "index";
    }

    /**
     * 测试自动跳转500页面
     * @return
     */
    @RequestMapping("/test2")
    public String test500(){

        return "index";
    }

    /**
     * 进入测试页面
     * @return
     */
    @RequestMapping("/test3")
    public String test3(){

        return "test";
    }

    @RequestMapping("/test4")
    public String test4(Model model){

        User user1 = new User("1","zs","123");
        User user2 = new User("2","ls","456");
        List<User> userList = new ArrayList<>();
        userList.add(user1);
        userList.add(user2);
        model.addAttribute("userList",userList);
        return "list";
    }

}
